import requests
from bs4 import BeautifulSoup
import time

url = 'http://www.ibiqu.org/52_52542/'

head = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36',
    'Referer': 'http://www.ibiqu.org/'
}

res = requests.get(url, headers=head)

html = res.text

soup = BeautifulSoup(html, 'lxml')

dd = soup.find_all('dd')[9:]

for d in dd:
    time.sleep(1)
    a = d.find("a")
    title = a.string
    href = 'http://www.ibiqu.org'+a.get("href")
    response = requests.get(href, headers=head)
    html1 = response.text
    soup1 = BeautifulSoup(html1, 'lxml')
    content = soup1.find('div',id='content')
    # content = soup1.select("#content")

    content = list(content.stripped_strings)

    contents = '\n'.join(content)

    with open(f"圣墟\{title}.txt", 'w', encoding='utf-8') as f:
        f.write(contents)

